package com.hkts.naturalgas.organizational.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.organizational.entity.HontRole;
import com.hkts.naturalgas.organizational.entity.HontUser;
import com.hkts.naturalgas.organizational.entity.HontUserRole;
import com.hkts.naturalgas.organizational.mapper.HontRoleMapper;
import com.hkts.naturalgas.organizational.mapper.HontUserMapper;
import com.hkts.naturalgas.organizational.mapper.HontUserRoleMapper;
import com.hkts.naturalgas.organizational.service.IHontUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-04-06
 */
@Service
@Transactional
public class HontUserRoleServiceImpl extends ServiceImpl<HontUserRoleMapper, HontUserRole> implements IHontUserRoleService {


@Autowired
private HontUserRoleMapper hontUserRoleMapper;

@Override
public IPage<HontUserRole> selectPage(Page<HontUserRole> page, HontUserRole hontUserRole){
        QueryWrapper<HontUserRole> query = Wrappers.query();
        QueryWrapper<HontUserRole> entityWrapper = getEntityWrapper(query, hontUserRole);
        return hontUserRoleMapper.selectPage(page, entityWrapper);
        }




@Override
public List<HontUserRole> selectList(HontUserRole hontUserRole){
        QueryWrapper<HontUserRole> query = Wrappers.query();
        QueryWrapper<HontUserRole> entityWrapper = getEntityWrapper(query, hontUserRole);
        return hontUserRoleMapper.selectList(entityWrapper);
        }


    /**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<HontUserRole> getEntityWrapper(QueryWrapper<HontUserRole> entityWrapper,HontUserRole hontUserRole){
        //条件拼接
                if(StringUtils.isNotBlank(hontUserRole.getCreateBy())){
                entityWrapper.like(HontUserRole.CREATE_BY,hontUserRole.getCreateBy());
                }
                /*if(StringUtils.isNotBlank(hontUserRole.getCreateTime())){
                entityWrapper.like(HontUserRole.CREATE_TIME,hontUserRole.getCreateTime());
                }
                if(StringUtils.isNotBlank(hontUserRole.getDelFlag())){
                entityWrapper.like(HontUserRole.DEL_FLAG,hontUserRole.getDelFlag());
                }*/
                if(StringUtils.isNotBlank(hontUserRole.getUpdateBy())){
                entityWrapper.like(HontUserRole.UPDATE_BY,hontUserRole.getUpdateBy());
                }
                /*if(StringUtils.isNotBlank(hontUserRole.getUpdateTime())){
                entityWrapper.like(HontUserRole.UPDATE_TIME,hontUserRole.getUpdateTime());
                }*/
                if(StringUtils.isNotBlank(hontUserRole.getHontRoleId())){
                entityWrapper.like(HontUserRole.HONT_ROLE_ID,hontUserRole.getHontRoleId());
                }
                if(StringUtils.isNotBlank(hontUserRole.getHontUserId())){
                entityWrapper.like(HontUserRole.HONT_USER_ID,hontUserRole.getHontUserId());
                }
        return entityWrapper;
        }
        }
